<include file="Public:header" />
<div id="table-advanced" class="row">
    <div class="col-lg-12">

        <div class="tab-content">
            <!-- 头部工具条开始 -->
            <div class="row mbm">
                <div id="div_toolsbar1">
                    <div class="col-lg-12">
                        <div class="pull-left pagination-panel"><span id="row_count"></span> &nbsp;&nbsp;&nbsp;
                            <a href="javascript:void()" class="btn btn-sm btn-default btn-prev gw-prev disabled"><i class="fa fa-angle-left"></i></a>&nbsp;
                            <input type="text" maxlenght="5" value="" id="input_top_page_num" class="pagination-panel-input form-control input-mini input-inline input-sm text-center gw-page">&nbsp;<a href="javascript:void()" class="btn btn-sm btn-default btn-prev gw-next"><i class="fa fa-angle-right"></i></a>&nbsp; 共 <span id="sp_1_pager_list_1_top"></span> 页 | 每页显示 &nbsp;
                            <span id="span_page_list"></span>&nbsp;&nbsp;条
                        </div>
                        <div class="pull-right right-toolbar">

                            <button class="btn btn-sm btn-default reload" style="margin-right:10px"><i class="fa fa-refresh"></i> 刷新</button>
                            <button class="btn btn-sm btn-default filter" style="margin-right:10px"><i class="fa fa-filter"></i> 筛选</button>
                          <!--
                            <button class="btn btn-sm btn-default btn-add-new" style="margin-right:10px"><i class="fa fa-plus"></i> 新建</button>-->

                        </div>

                    </div>
                </div>
                <div id="div_toolsbar2" style="display:none">
                    <div class="col-lg-8">
                        <div class="pull-left pagination-panel" style="padding-top:7px;">已选中 <span></span> 条 &nbsp;
                        </div>
                        <div class="pull-left right-toolbar">
                          
                              <button class="btn btn-sm btn-default delete" style="margin-right:10px"><i class="glyphicon glyphicon-trash"></i> 删除</button>
                                                    
                       </div>
                    </div>
                </div>
            </div>
            <!-- 头部工具条结束 -->
            <!--  公共的表格部分开始 -->
            <div class="jqGrid_wrapper" id="jqgrid_table_list1">
                <table id="table_list_1"></table>
                <div id="pager_list_1"></div>
            </div>
            <!--  公共的表格部分结束 -->
        </div>
    </div>
</div>



<script>


var a;
var $row_count = $('#row_count'),
        $table = $('#table_list_1'),
        // tabid = '{$tabid}',
        menu = '{$menu}';
base_url = '__APP__/index.php/PositionApply/getData/'
$pager_list = $('#pager_list_1');

var user_custom_col = '{$user_custom_col_json}';
var colset_li  = '<div class="list_box_li"></div>';
var colset_show_lis = '';

$(document).ready(function () {

    $.jgrid.defaults.styleUI = 'Bootstrap';

    // Configuration for jqGrid Example 1

    $table.jqGrid({
        url:base_url,
        datatype: "json",
        height: 'auto',
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [10, 20, 30],
        colNames: ["ID","申请职位","姓名","邮箱","手机","简历下载","删除"],
                colModel: [{name:'id',index:'id',editable:true,formatter:FmatterCustomerName},
                           {name:'position_name',index:'position_name',editable:true,formatter:FmatterCustomerName},
                           {name:'name',index:'name',editable:true,formatter:FmatterCustomerName},
                           {name:'email',index:'email',editable:true,formatter:FmatterCustomerName},
                           {name:'mobile',index:'mobile',editable:true,formatter:FmatterCustomerName},
                           {name:'resume',index:'resume',editable:true,formatter:formatResume},
                           {name:'id',index:'action',editable:true,formatter:formatAction},
                           ],
        pager: $pager_list,
        viewrecords: true,
        multiselect : true,
        recordpos:'left',
        hidegrid: false,
        autowidth: true,
        loadtext:'正在很努力的加载...',
        gridComplete: function(id){
            init_top_page();
        },
    });


    // Add responsive to jqGrid
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list_1').setGridWidth(width);
    });

    //右上侧工具条 绑定点击事件
    $table.jqGrid('filterToolbar',{searchOperators : false, searchOnEnter: true, enableClear: false });
    $('.ui-search-toolbar').toggle();
    $('.right-toolbar button').click(function(){
        if($(this).hasClass('filter')){
            $('.ui-search-toolbar').toggle();
        }else if($(this).hasClass('reload')){
            $table.trigger("reloadGrid");
            //新建
        }else if($(this).hasClass('btn-add-new')){
           window.location.href = '__APP__/index.php/Positions/add/'+'&t=' + Math.random(1000);
            //导入
        }else if($(this).hasClass('btn-import')){
            parent.layer.open({
                type: 2,//iframe打开
                shadeClose: true,
                shade: 0.8,
                area: ['790px', '360px'], //宽高
                title: '导入',
                content: '{:U("customer/excelimport")}&t=' + Math.random(1000) //iframe的url
            });
            //编辑显示字段
        }else if($(this).hasClass('customSortMenu')){
            $.get('{:U("customer/customSortMenu")}'+'&t=' + Math.random(1000), '', function(data){
                parent.layer.open({
                    type: 1,
                    area: ['400px', '550px'], //宽高
                    title: '编辑显示字段',
                    shadeClose:true, //点击遮罩层 关闭
                    content: data
                });
            })
            //退回公海池
        }else if($(this).hasClass('return-sea-index')){
            var ids = getSelectRow();
            if(!ids) return false;
            $.get('{:U("customer/returnSea")}'+'&t=' + Math.random(1000),'&ids='+ids, function(data){
                parent.layer.open({
                    type: 1,
                    area: ['450px', '320px'],
                    title: '退回公海',
                    shadeClose:true,
                    content: data
                });
            })
            //删除
        }else if($(this).hasClass('delete')){
            var ids = getSelectRow();
            if(!ids) return false;

            var url = '__APP__/index.php/Positions/delete/';
            ajax_do(url,"ids="+ids,true,"确定要删除这些吗？");
            //彻底删除
        }else if($(this).hasClass('complete_delete')){
            var ids = getSelectRow();
            if(!ids) return false;

            var url = '{:U("customer/completeDelete")}&ids='+ids;
            ajax_do(url,"",true,"确定要彻底删除吗？此操作不可恢复");
            //恢复
        }else if($(this).hasClass('recover')){
            var ids = getSelectRow();
            if(!ids) return false;

            var url = '{:U("customer/recover")}&ids='+ids;
            ajax_do(url,"",true,"确定要恢复这些数据吗？");
            //导出
        }else if($(this).hasClass('merge')){
            var ids = getSelectRow();
            if(!ids) return false;
            var url = '{:U("customer/excelExport")}&ids='+ids;
            //ajax_do(url,"",true,"确定要导出这些数据吗？");
            window.location.href = url;
        }
    });
});

function init_top_page(){
    $row_count.html($("#pager_list_1_left div").html());
    $("#input_top_page_num").val($("#input_pager_list_1 input").val());
    $("#sp_1_pager_list_1_top").html($("#sp_1_pager_list_1").html());

    //绑定翻页事件
    //下一页
    if($("#next_pager_list_1").attr("class") == "ui-pg-button"){
        $(".gw-next").removeClass('disabled');
        $(".gw-next").click(function(){
            $("#next_pager_list_1").trigger('click');
        });

    }else{
        $(".gw-next").addClass('disabled');
    }

    if($("#prev_pager_list_1").attr("class") == "ui-pg-button"){
        $(".gw-prev").removeClass('disabled');
        $(".gw-prev").click(function(){
            $("#prev_pager_list_1").trigger('click');
        });

    }else{
        $(".gw-prev").addClass('disabled');
    }

    $('#dataInput').bind('keypress',function(event){
        if(event.keyCode == "13")
        {
            alert('你输入的内容为：' + $('#dataInput').val());
        }
    });

    $("#input_top_page_num").bind('keypress',function(event){
        if(event.keyCode == "13")
        {
            var i = $('#input_top_page_num').val();
            $("#input_pager_list_1 input").val(i);
            $table.jqGrid('setGridParam',{page:i}).trigger("reloadGrid");
        }
    });

    //复制每页显示多少的下拉框
    $("#span_page_list").html($("#pager_list_1_center .ui-pg-selbox").clone().attr("class","form-control input-sm input-inline"));
    $("#span_page_list select").val($("#pager_list_1_center .ui-pg-selbox").val());
    $("#span_page_list select").change(function(){
        var i = $(this).children('option:selected').val()
        $("#pager_list_1_center .ui-pg-selbox").val(i);
        $table.jqGrid('setGridParam',{rowNum:i}).trigger("reloadGrid");

    });

    //绑定勾选框
    $(".jqGrid_wrapper .cbox").click(function(){
        var _obj_length = $('.jqGrid_wrapper input:checked').length;
        if($("#cb_table_list_1").attr("checked") == "checked") _obj_length -- ;
        if(_obj_length>0){
            $('#div_toolsbar1').hide();
            $('#div_toolsbar2').show();
            $('#div_toolsbar2 span').text(_obj_length);

        }else{
            $('#div_toolsbar2').hide();
            $('#div_toolsbar1').show();
        }
    });

    //当页面重载的时候，勾选项就没有了，所以把2隐藏
    $('#div_toolsbar2').hide();
    $('#div_toolsbar1').show();

}


//格式化客户
function FmatterCustomerName(cellvalue, options, rowObject){
    if(rowObject.is_deleted == 1){
        return cellvalue;
    }else{
        if(cellvalue != null && cellvalue.indexOf("|") > 0 ){
            var arr = cellvalue.split("|");
            //console.log(arr);
            return "<a href='javascript:view_Customer("+arr[0]+");'>"+arr[1]+"</a>";
        }else{
            //return "<a href='javascript:view_Customer("+rowObject.customer_id+");'>"+cellvalue+"</a>";
            return cellvalue;
        }
    }



};
//格式化联系人
function FmatterContactsName(cellvalue, options, rowObject){
    return "<a href='javascript:view_Contacts("+rowObject.contacts_id+");'>"+cellvalue+"</a>";
};


function FmatterUserName(cellvalue, options, rowObject){
    if(cellvalue != null && cellvalue.indexOf("|") > 0 ){
        var arr = cellvalue.split("|");
        //console.log(arr);
        return "<a href='javascript:view_OwnerUser("+arr[0]+");'>"+arr[1]+"</a>";
    }else{
        return cellvalue;
    }
};

//格式化联系人
function FmatterStatus(cellvalue, options, rowObject){
    return cellvalue=="1" ? "上线":"隐藏";
};

//格式化联系人
function FmatterStatus_2(cellvalue, options, rowObject){
    return cellvalue=="undefined" ? "有":"0";
};

function formatResume(cellvalue,options,rowObject){
	return "<a href=\""+cellvalue+"\" target=\"_blank\">下载</a>";
}


//格式化状态
function formatAction(cellvalue, options, rowObject){
    //return "<a class=\"edit\" href=\"javascript:edit_Item("+cellvalue+")\" rel=\""+cellvalue+"\">编辑</a> &nbsp;&nbsp;&nbsp;&nbsp;<a class=\"delete\" href=\"javascript:delete_Item("+cellvalue+")\" rel=\""+cellvalue+"\">删除</a>";
    return "<a class=\"delete\" href=\"javascript:delete_Item("+cellvalue+")\" rel=\""+cellvalue+"\">删除</a>";
};


function edit_Item(id){
    window.location.href= '__APP__/index.php/Positions/edit/id/'+id+'/t/' + Math.random(1000);
}

//反馈页面
function feedback_Item(id){
    window.location.href= '__APP__/index.php/PositionApply/feedback/job_id/'+id+'/t/' + Math.random(1000);
}

//删除页面
function delete_Item(id){
    var url = '__APP__/index.php/PositionApply/delete/';
    ajax_do(url,"id="+id,true,"确定要删除这条数据吗？");
}


//请求一个url，返回结果并显示，可以设置是否弹出确问询
function ajax_do(url,param,show_confirm ,confirm_title,confirm_text){
    if(show_confirm){
        swal({
                    title: confirm_title,
                    text: confirm_text,
                    type: "info",
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    showCancelButton: true,
                    closeOnConfirm: false,
                    showLoaderOnConfirm: true,
                },
                function(){
                    $.post(url+'&t=' + Math.random(1000),param, function(data){
                        swal.close();
                        parent.layer.open({
                            type: 1,
                            title: false,
                            closeBtn: false,
                            shadeClose:true, //点击遮罩层 关闭
                            content: data,
                            end: function(index){
                                $table.trigger("reloadGrid");
                            }
                        });

                    }, 'html');

                });
    }else{
        $.post(url+'&t=' + Math.random(1000),param, function(data){
            parent.layer.open({
                type: 1,
                title: false,
                closeBtn: false,
                shadeClose:true, //点击遮罩层 关闭
                content: data,
                end: function(index){
                    //parent.layer.closeAll();
                    $table.trigger("reloadGrid");
                }
            });

        }, 'html');

    }

}



//获取选中的行，返回ids ，如3,4,7
function getSelectRow(){
    var arr = $table.jqGrid('getGridParam','selarrrow');
    if(arr.length == 0){
        parent.layer.msg("请选择数据", {icon: 3});
        return false;
    }else{
        return arr.join(',');
    }
}

function view_Customer(id){
    showPanel(_root_path+'/index.php?m=customer&a=view&id='+id);
}

function view_OwnerUser(id){
    $.get('{:U('user/view')}'+'&id='+id+'&t=' + Math.random(1000), '', function(data){
        parent.layer.open({
            type: 1,
            //skin: 'layui-layer-rim', //加上边框
            area: ['600px', '470px'], //宽高
            title: '资料',
            shadeClose:true, //点击遮罩层 关闭
            content: data
        });
    })
}

$(".fa-send-o").parent().parent().addClass("active");  //一级栏目
//二级栏目需要添加active样式
$(".fa-briefcase:eq(1)").addClass("active");
</script>
<include file="Public:footer" />
		